package test;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;

import observer.Observer;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class testObserverMain  {
	
	testObserver observer1;
	testObserver observer2;
	testObserver observer3;
	
	testSubject subject;
	ArrayList<Observer> observerList;
	
	@Before 
	public void setUp() throws Exception {
		subject = new testSubject();
		
		observer1 = new testObserver( subject );
		observer1.setName("observer1");
		
		observer2 = new testObserver( subject );
		observer2.setName("observer2");
		
	}
	
	@After 
	public void tearDown() throws Exception {
		observer1 = null;
		observer2 = null;
		subject = null;
	}
	
	
	@Test
	public void testAddObserver(){
		
		subject.addObserver(observer1);
		observerList = subject.getObservers();
		assertEquals("observer1", observerList.get(0).getName() );

		
		subject.addObserver(observer2);
		assertEquals("observer2", observerList.get(1).getName() );

	}
	
	@Test
	public void testDeleteObserver(){
		
		observerList = subject.getObservers();
		assertEquals(0, observerList.size());
		subject.addObserver(observer1);
		assertEquals(1, observerList.size());
		subject.deleteObserver(observer1);
		assertEquals(0, observerList.size());
	}
	
	@Test
	public void testNotify(){
		subject.addObserver(observer1);
		assertEquals( false, observer1.getCall());
		subject.setValue(10);
		assertEquals(10, subject.getValue());
		assertEquals( true, observer1.getCall() );
		
	}
}